package com.mall.goods.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.goods.mapper.CmsSubjectMapper;
import com.mall.model.domain.CmsSubject;
import com.mall.model.vo.CommonPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CmsSubjectService extends ServiceImpl<CmsSubjectMapper, CmsSubject> {

    @Autowired(required = false)
    private CmsSubjectMapper cmsSubjectMapper;

    /**
     * 根据专题名称分页获取商品专题
     *
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    public CommonPage list(String keyword, Integer pageNum, Integer pageSize) {
        Page<CmsSubject> pageInfo = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<CmsSubject> queryWrapper = new LambdaQueryWrapper<>();
        //查询条件
        queryWrapper.like(keyword != null, CmsSubject::getTitle, keyword);
        Integer count = cmsSubjectMapper.selectCount(queryWrapper);
        cmsSubjectMapper.selectPage(pageInfo, queryWrapper);
        return new CommonPage(pageNum, pageSize, count, pageInfo.getRecords());
    }

    /**
     * 获取全部商品专题
     *
     * @return
     */
    public List listAll() {
        List<CmsSubject> list = list();
        return list;
    }
}
